home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 1998 November / IRIX 6.5.2 Base Documentation November 1998.img / usr / share / catman / u_man / cat1 / a2p.z / a2p
Text File  |  1998-10-30  |  8KB  |  265 lines

  1.  
  2.  
  3.  
  4. AAAA2222PPPP((((1111))))                                                                  AAAA2222PPPP((((1111))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      a2p - Awk to Perl translator
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      aaaa2222pppp [[[[ooooppppttttiiiioooonnnnssss]]]] ffffiiiilllleeeennnnaaaammmmeeee
  13.  
  14. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  15.      _A_2_p takes an awk script specified on the command line (or from standard
  16.      input) and produces a comparable _p_e_r_l script on the standard output.
  17.  
  18.      OOOOppppttttiiiioooonnnnssss
  19.  
  20.      Options include:
  21.  
  22.      ----DDDD<<<<nnnnuuuummmmbbbbeeeerrrr>>>>
  23.           sets debugging flags.
  24.  
  25.      ----FFFF<<<<cccchhhhaaaarrrraaaacccctttteeeerrrr>>>>
  26.           tells a2p that this awk script is always invoked with this ----FFFF
  27.           switch.
  28.  
  29.      ----nnnn<<<<ffffiiiieeeellllddddlllliiiisssstttt>>>>
  30.           specifies the names of the input fields if input does not have to be
  31.           split into an array.  If you were translating an awk script that
  32.           processes the password file, you might say:
  33.  
  34.                   a2p -7 -nlogin.password.uid.gid.gcos.shell.home
  35.  
  36.           Any delimiter can be used to separate the field names.
  37.  
  38.      ----<<<<nnnnuuuummmmbbbbeeeerrrr>>>>
  39.           causes a2p to assume that input will always have that many fields.
  40.  
  41.      ----oooo   tells a2p to use old awk behavior.  For now, the only difference is
  42.           that old awk always has a line loop, even if there are no line
  43.           actions, whereas new awk does not.
  44.  
  45.      """"CCCCoooonnnnssssiiiiddddeeeerrrraaaattttiiiioooonnnnssss""""
  46.  
  47.      A2p cannot do as good a job translating as a human would, but it usually
  48.      does pretty well.  There are some areas where you may want to examine the
  49.      perl script produced and tweak it some.  Here are some of them, in no
  50.      particular order.
  51.  
  52.      There is an awk idiom of putting _i_n_t() around a string expression to
  53.      force numeric interpretation, even though the argument is always integer
  54.      anyway.  This is generally unneeded in perl, but a2p can't tell if the
  55.      argument is always going to be integer, so it leaves it in.  You may wish
  56.      to remove it.
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. AAAA2222PPPP((((1111))))                                                                  AAAA2222PPPP((((1111))))
  71.  
  72.  
  73.  
  74.      Perl differentiates numeric comparison from string comparison.  Awk has
  75.      one operator for both that decides at run time which comparison to do.
  76.      A2p does not try to do a complete job of awk emulation at this point.
  77.      Instead it guesses which one you want.  It's almost always right, but it
  78.      can be spoofed.  All such guesses are marked with the comment "#???".
  79.      You should go through and check them.  You might want to run at least
  80.      once with the ----wwww switch to perl, which will warn you if you use == where
  81.      you should have used eq.
  82.  
  83.      Perl does not attempt to emulate the behavior of awk in which nonexistent
  84.      array elements spring into existence simply by being referenced.  If
  85.      somehow you are relying on this mechanism to create null entries for a
  86.      subsequent for...in, they won't be there in perl.
  87.  
  88.      If a2p makes a split line that assigns to a list of variables that looks
  89.      like (Fld1, Fld2, Fld3...) you may want to rerun a2p using the ----nnnn option
  90.      mentioned above.  This will let you name the fields throughout the
  91.      script.  If it splits to an array instead, the script is probably
  92.      referring to the number of fields somewhere.
  93.  
  94.      The exit statement in awk doesn't necessarily exit; it goes to the END
  95.      block if there is one.  Awk scripts that do contortions within the END
  96.      block to bypass the block under such circumstances can be simplified by
  97.      removing the conditional in the END block and just exiting directly from
  98.      the perl script.
  99.  
  100.      Perl has two kinds of array, numerically-indexed and associative.  Perl
  101.      associative arrays are called "hashes".  Awk arrays are usually
  102.      translated to hashes, but if you happen to know that the index is always
  103.      going to be numeric you could change the {...} to [...].  Iteration over
  104.      a hash is done using the _k_e_y_s() function, but iteration over an array is
  105.      NOT.  You might need to modify any loop that iterates over such an array.
  106.  
  107.      Awk starts by assuming OFMT has the value %.6g.  Perl starts by assuming
  108.      its equivalent, $#, to have the value %.20g.  You'll want to set $#
  109.      explicitly if you use the default value of OFMT.
  110.  
  111.      Near the top of the line loop will be the split operation that is
  112.      implicit in the awk script.  There are times when you can move this down
  113.      past some conditionals that test the entire record so that the split is
  114.      not done as often.
  115.  
  116.      For aesthetic reasons you may wish to change the array base $[ from 1
  117.      back to perl's default of 0, but remember to change all array subscripts
  118.      AND all _s_u_b_s_t_r() and _i_n_d_e_x() operations to match.
  119.  
  120.      Cute comments that say "# Here is a workaround because awk is dumb" are
  121.      passed through unmodified.
  122.  
  123.      Awk scripts are often embedded in a shell script that pipes stuff into
  124.      and out of awk.  Often the shell script wrapper can be incorporated into
  125.      the perl script, since perl can start up pipes into and out of itself,
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. AAAA2222PPPP((((1111))))                                                                  AAAA2222PPPP((((1111))))
  137.  
  138.  
  139.  
  140.      and can do other things that awk can't do by itself.
  141.  
  142.      Scripts that refer to the special variables RSTART and RLENGTH can often
  143.      be simplified by referring to the variables $`, $& and $', as long as
  144.      they are within the scope of the pattern match that sets them.
  145.  
  146.      The produced perl script may have subroutines defined to deal with awk's
  147.      semantics regarding getline and print.  Since a2p usually picks
  148.      correctness over efficiency.  it is almost always possible to rewrite
  149.      such code to be more efficient by discarding the semantic sugar.
  150.  
  151.      For efficiency, you may wish to remove the keyword from any return
  152.      statement that is the last statement executed in a subroutine.  A2p
  153.      catches the most common case, but doesn't analyze embedded blocks for
  154.      subtler cases.
  155.  
  156.      ARGV[0] translates to $ARGV0, but ARGV[n] translates to $ARGV[$n].  A
  157.      loop that tries to iterate over ARGV[0] won't find it.
  158.  
  159. EEEENNNNVVVVIIIIRRRROOOONNNNMMMMEEEENNNNTTTT
  160.      A2p uses no environment variables.
  161.  
  162. AAAAUUUUTTTTHHHHOOOORRRR
  163.      Larry Wall <_l_a_r_r_y@_w_a_l_l._o_r_g>
  164.  
  165. FFFFIIIILLLLEEEESSSS
  166. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  167.       perl   The perl compiler/interpreter
  168.  
  169.       s2p    sed to perl translator
  170.  
  171.  
  172. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  173. BBBBUUUUGGGGSSSS
  174.      It would be possible to emulate awk's behavior in selecting string versus
  175.      numeric operations at run time by inspection of the operands, but it
  176.      would be gross and inefficient.  Besides, a2p almost always guesses
  177.      right.
  178.  
  179.      Storage for the awk syntax tree is currently static, and can run out.
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195.                                                                         PPPPaaaaggggeeee 3333
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202. AAAA2222PPPP((((1111))))                                                                  AAAA2222PPPP((((1111))))
  203.  
  204.  
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.  
  235.  
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.                                                                         PPPPaaaaggggeeee 4444
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.